iT邦幫忙

0

Angular 環境(environment.ts)設定

  • 分享至 

  • xImage
  •  

給自己看的筆記XD

預設會有兩個檔案
environment.ts
environment.prod.ts

平時在本機建置時(ng s)讀取的會是environment.ts
ng build => environment.ts
ng build --prod => environment.prod.ts

如果要新增環境設定檔,去angular.json => configurations 下面新增,比如叫dev

          "configurations": {
            "dev": {
              "fileReplacements": [
              <font color=#800000>酒紅色</font>
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.dev.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }

然後新增一個檔案取名叫做 environment.dev.ts
build的時候下參數 ng build --prod --configuration=dev

就會去吃dev的設定了


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言